﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Microsoft.Practices.Unity;

namespace Framework
{
	public class ViewPageActivator : IViewPageActivator
	{
		private readonly IUnityContainer container;

		public ViewPageActivator(IUnityContainer container)
		{
			this.container = container;
		}

		public object Create(ControllerContext controllerContext, Type type)
		{
			object viewPage = container.IsRegistered(type) ? container.Resolve(type) : null;

			if (viewPage != null)

				return viewPage;

			return Activator.CreateInstance(type);
		}
	}
}
